package com.agricultural.machine.path;

import java.util.HashMap;
import java.util.Map;

/**
 * 路径策略工厂 - 策略模式+工厂模式
 */
public class PathStrategyFactory {
    private static PathStrategyFactory instance;
    private final Map<String, PathStrategy> strategies;
    private final String[] strategyNames = {"direct", "avoidObstacle", "terrainOptimized"};
    
    private PathStrategyFactory() {
        this.strategies = new HashMap<>();
        strategies.put("direct", new DirectPathStrategy());
        strategies.put("avoidObstacle", new AvoidObstaclePathStrategy());
        strategies.put("terrainOptimized", new TerrainOptimizedPathStrategy());
    }
    
    public static synchronized PathStrategyFactory getInstance() {
        if (instance == null) {
            instance = new PathStrategyFactory();
        }
        return instance;
    }
    
    /**
     * 获取路径策略
     */
    public PathStrategy getStrategy(String strategyName) {
        PathStrategy strategy = strategies.get(strategyName);
        if (strategy == null) {
            throw new IllegalArgumentException("不支持的路径策略: " + strategyName);
        }
        return strategy;
    }
    
    /**
     * 获取默认策略
     */
    public PathStrategy getDefaultStrategy() {
        return strategies.get("direct");
    }
    
    /**
     * 获取所有策略
     */
    public PathStrategy[] getAllStrategies() {
        return strategies.values().toArray(new PathStrategy[0]);
    }
    
    /**
     * 获取策略名称数组
     */
    public String[] getStrategyNames() {
        return strategyNames;
    }
} 